package 集合.List集合;

import java.util.ArrayList;     //导包
import java.util.List;          //导包

public class Test {
    public static void main(String[] args) {

        //（1）先导包，再创建集合对象
        List list=new ArrayList();
        //（2）创建元素对象
        Student student1=new Student("雷军",35,"小米CEO");
        Student student2=new Student("马云",40,"阿里巴巴CEO");
        Student student3=new Student("马化腾",45,"腾讯CEO");
        Student student4=new Student("任正非",50,"华为CEO");
        System.out.println(student1);//默认调用toString()方法
        System.out.println(student1.toString()+"一样");//默认调用toString()方法
        System.out.println(student2);
        System.out.println(student3);
        System.out.println(student4);
        System.out.println("------------------------");
        //（3）将元素对象添加到集合对象中
        //测试public boolean add(E e):将数据添加到集合末尾，E为泛型的意思，且先理解为Object类型
        boolean bol1=list.add(student1);
        boolean bol2=list.add(student1);
        boolean bol3=list.add(student2);
        boolean bol4=list.add(student3);
        boolean bol5=list.add(student4);
        //（4）遍历集合
        //测试public int size():获取集合长度
        for (int i = 0; i < list.size(); i++) {

        //测试public E get(int index):根据索引，索取其对应的元素
            Object obj=list.get(i);
            System.out.println("索引为"+i+"的元素为:"+obj);
        }

    }
}
